<template>
  <div style="width: 50%;margin:0 auto;">
    <el-form :label-position="labelPosition" label-width="80px" :model="fromData">
      <el-form-item label="用户名">
        <el-input v-model="fromData.username"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input type="password" v-model="fromData.password"></el-input>
      </el-form-item>
      <el-button @click="login" :loading="isLoad">登录</el-button>
    </el-form>
  </div>
</template>

<script>
import { Login } from "../../utils/http";
export default {
  name: "",
  data() {
    return {
      labelPosition: "left",
      fromData: {
        username: "",
        password: "",
      },
      isLoad: false,
    };
  },
  methods: {
    login() {
      if (!this.fromData.username || !this.fromData.password) {
        alert("用户名或密码不能为空");
        return;
      }
      if (this.fromData.username !== "admin") {
        this.$message("用户名不正确");
        return;
      }
      if (this.fromData.password !== "admin") {
        this.$message("密码不正确");
        return;
      }
      this.isLoad = true;
      Login(this.fromData).then((res) => {
        localStorage.setItem("user", res.data.username);
        this.isLoad = false;
        this.$router.push('/')
        this.$message("登录成功");
      });
    },
  },
  created() {},
  mounted() {},
  components: {},
};
</script>

<style scoped>
</style>
